<extend name="./public/frame.html"/>
<block name="content">
    <div class="layui-row">
        <div class="layui-col-xs12 layui-col-md6 layui-col-lg4">
            <div class="layui-form">
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <div class="layui-inline">
                            <input type="text" class="layui-input date" readonly id="start" placeholder="登录时间--起">
                        </div>
                        <div class="layui-inline">
                            <input type="text" class="layui-input date" readonly id="end" placeholder="登录时间--止">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-md4 layui-col-lg2">
            <div class="layui-form">
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" lay-verify="required|title" required placeholder="请输入手机号"
                               class="layui-input" id="user_phone">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6 layui-col-md4 layui-col-lg3">
            <div class="layui-btn-group">
                <button class="layui-btn" data-type="search">搜索</button>
                <button class="layui-btn layui-btn-disabled" data-type="" id="reset">复位</button>
            </div>
        </div>
    </div>
    <table class="layui-table"
           lay-data="{width:'auto', height:'auto', url:'{:url('table')}', page: true, limit: 10, id:'log'}"
           lay-filter="log">
        <thead>
        <tr>
            <th lay-data="{checkbox:true, fixed: true}"></th>
            <th lay-data="{field:'log_id', fixed: true, width:80, sort: true}">ID</th>
            <th lay-data="{field:'uid', fixed: true, width:100}">用户ID</th>
            <th lay-data="{field:'user_phone', width:120, sort: true}">手机号</th>
            <th lay-data="{field:'login_local', width:200}">登录坐标</th>
            <th lay-data="{field:'login_time', width:160, sort: true}">登录时间</th>
            <th lay-data="{field:'login_ip',width:160}">登录IP</th>
            <th lay-data="{field:'login_IMEI',width:150}">登录IMEI</th>
            <th lay-data="{field:'login_IMSI',width:150}">登录IMSI</th>
            <th lay-data="{field:'login_MAC',width:150}">登录MAC</th>
            <th lay-data="{fixed:'right', toolbar: '#barDemo', width:100, align:'center'}">操作</th>
        </tr>
        </thead>
    </table>
    <script type="text/html" id="barDemo">
        {{#if(d.login_local){}}
        <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="local">登录地点</a>
        {{#}else{}}
        <a class="layui-btn layui-btn-xs layui-btn-disabled" >登录地点</a>
        {{#}}}
    </script>
    <script type="application/javascript">
        layui.use(['table', 'laytpl', 'laydate','form'], function () {
            var table = layui.table
                , laydate = layui.laydate;
            lay('.date').each(function(){
                laydate.render({
                    elem: this
                    , theme: 'molv'
                    ,type: 'date'
                    ,trigger: 'click'
                });
            });

            //监听工具条
            table.on('tool(log)', function (obj) {
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var local = data.login_local;
                if (layEvent === 'local') {
                    layer.open({
                        type: 2,
                        title: [data.user_phone+'登录时间'+data.login_time+'的登录地点','color:red;'],
                        shadeClose: true,
                        shade: 0.8,
                        area: ['100%', '100%'],
                        content: '{$local}?center=' + local //iframe的url
                    });
                }
            });

            var $ = layui.jquery, active = {
                search: function () {
                    var start = $('#start').val();
                    var end = $('#end').val();
                    var user_phone = $('#user_phone').val();
                    var reset = $('#reset');
                    if (start||end||user_phone) {
                        reset.removeClass('layui-btn-disabled').addClass('layui-btn-normal').data('type', 'reset');
                        table.reload('log', {
                            url: '/admin/user_login_log/search',
                            where: {
                                start: start,
                                end: end,
                                user_phone: user_phone
                            } //设定异步数据接口的额外参数
                        });
                    } else {
                        reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
                        layer.alert('搜索项不能为空');
                    }
                }
                , reset: function () {
                    var reset = $('#reset');
                    if (reset.data('type') !== '') {
                        table.reload('log', {
                            url: '/admin/user_login_log/table',where:{}
                        });
                    }
                    $('.layui-input').each(function () {                        $(this).val('');                    });                $('.layui-this').each(function () {$(this).removeClass('layui-this');});
                    reset.removeClass('layui-btn-normal').addClass('layui-btn-disabled').data('type', '');
                }
            };
            $('.layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });

    </script>
</block>
